home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / MOUSE1.PRG < prev    next >
Text File  |  1992-10-17  |  46KB  |  1,557 lines

  1. /*
  2.  * File......: MOUSE1.PRG
  3.  * Author....: Leo Letendre
  4.  * CIS ID....: 73607,233
  5.  * Date......: $Date:   17 Oct 1992 16:28:58  $
  6.  * Revision..: $Revision:   1.9  $
  7.  * Log file..: $Logfile:   C:/nanfor/src/mouse1.prv  $
  8.  * 
  9.  * This is an original work by Robert DiFalco and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   C:/nanfor/src/mouse1.prv  $
  16.  * 
  17.  *    Rev 1.9   17 Oct 1992 16:28:58   GLENN
  18.  * Leo cleaned up documentation blocks.
  19.  * 
  20.  *    Rev 1.8   28 Sep 1992 01:38:14   GLENN
  21.  * Leo added FT_MGETSENS(), FT_MSETSENS(), FT_MSETPAGE(), FT_MGETPAGE(),
  22.  * and FT_MVERSION().
  23.  * 
  24.  * 
  25.  *    Rev 1.7   01 Jul 1992 01:45:18   GLENN
  26.  * Leo added documentation to FT_MDEFCRS and others. Added FT_MCONOFF(),
  27.  * FT_MINIT(), FT_MGETCOORD() and FT_MSETCOORD().  Restructured
  28.  * FT_MGETX() and FT_MGETY() for possible speed improvement and MAIN to
  29.  * better demonstrate some of the concerns when programming the mouse. 
  30.  * Added ability to change the number of rows and columns to demonstrate
  31.  * use in 43, 50 row mode etc. which is now supported in FT_MRESET() and
  32.  * FT_MINIT().
  33.  * 
  34.  *    Rev 1.6   23 Sep 1991 01:14:38   GLENN
  35.  * Corrected errors in syntax documention for FT_MBUTPRS() and FT_MDBLCLK(),
  36.  * found by Nantucket's Steve Silverwood.
  37.  * 
  38.  *    Rev 1.5   17 Aug 1991 15:34:52   GLENN
  39.  * Don Caton fixed some spelling errors in the doc
  40.  * 
  41.  *    Rev 1.4   15 Aug 1991 23:06:24   GLENN
  42.  * Forest Belt proofread/edited/cleaned up doc
  43.  * 
  44.  *    Rev 1.3   17 Jul 1991 22:28:40   GLENN
  45.  * Leo fixed a potential bug in ft_mcursor().
  46.  * 
  47.  *    Rev 1.2   27 May 1991 13:40:30   GLENN
  48.  * Leo Letendre sent me a revision of MOUSE1.PRG where he built in support
  49.  * for a three-button mouse, and revised the "double click" detection 
  50.  * algorithm.
  51.  *  
  52.  * Brought in compliance with new ft_int86().
  53.  * 
  54.  *    Rev 1.1   11 May 1991 00:16:48   GLENN
  55.  * ft_mgetpos() had a bug where the x and y coordinates were reversed. 
  56.  * Changed x coordinate to aRegs[3] and y coordinate to aRegs[4], just
  57.  * like in ft_msetpos().
  58.  * 
  59.  *    Rev 1.0   01 Apr 1991 01:01:48   GLENN
  60.  * Nanforum Toolkit
  61.  *
  62.  */
  63.  
  64.  
  65. // The original mouse routines were written by Robert diFalco but
  66. // Leo Letendre has made such major additions and modifications
  67. // and fixes that I've given him sole credit. -- G. Scott
  68.  
  69.  
  70. #include "FTINT86.CH"
  71.  
  72. static aReg[INT86_MAX_REGS]
  73. static lCrsState:=.F.
  74. static lMinit:=.F.
  75.  
  76. #ifdef FT_TEST
  77.  
  78.   FUNCTION MAIN(nRow,nCol)
  79.  
  80. * Pass valid row and column values for different video modes to change modes
  81.  
  82.      local nX, nY, cSavClr
  83.      local cSavScr := savescreen( 0, 0, maxrow(), maxcol() )
  84.      local nXm, nYm
  85.      local nSaveRow:=MAXROW()+1, nSaveCol:=MAXCOL()+1
  86.      local nMinor, nType, nIRQ
  87.      local aType:={"Bus","Serial","InPort","PS/2","HP"}
  88.      local nHoriz, nVert, nDouble
  89.      local nTime
  90.  
  91.     IF nRow=NIL
  92.         nRow=MAXROW()+1
  93.     ELSE
  94.         nRow=VAL(nRow)
  95.     ENDIF
  96.  
  97.     IF nCol=NIL
  98.         nCol=MAXCOL()+1
  99.     ELSE
  100.         nCol=VAL(nCol)
  101.     ENDIF
  102.  
  103.     IF .NOT.SETMODE(nRow,nCol)
  104.         @maxrow(),0 SAY "Mode Change unsuccessful:"+STR(nRow,2,0)+" by";
  105.             +STR(nCol,3,0)
  106.         RETURN NIL
  107.     ENDIF
  108.  
  109.      if empty( FT_MINIT() )
  110.         @ maxrow(), 0 say "Mouse driver is not installed!"
  111.         SETMODE(nSaveRow,nSaveCol)
  112.         return ""
  113.      endif
  114.  
  115.      * ..... Set up the screen
  116.      cSavClr := setcolor( "w/n" )
  117.      @ 0,0,maxrow(),maxcol() box "░░░░░░░░░"
  118.  
  119.      setcolor( "GR+/RB" )
  120.      scroll( 7,2,19,63,0 )
  121.      @ 7,2 to 20,63
  122.  
  123.      @ 17, 10 to 19, 40 double
  124.  
  125.      setcolor( "N/W" )
  126.      @ 18, 11 say "  Double Click here to Quit  "
  127.  
  128.      setcolor( "GR+/RB" )
  129.  
  130.      * ..... Start the demo
  131.  
  132.     @MAXROW(),0 SAY "Driver version: "+;
  133.         ALLTRIM(STR(FT_MVERSION(@nMinor,@nType,@nIRQ),2,0))+"."+;
  134.         ALLTRIM(STR(nMinor,2,0))
  135.      @ ROW(),COL() SAY " "+aType[nType]+" mouse using IRQ "+STR(nIRQ,1,0)
  136.  
  137.      FT_MGETSENS(@nHoriz,@nVert,@nDouble)  // Get the current sensitivities
  138.     FT_MSETSENS(70,70,60)    // Bump up the sensitivity of the mouse
  139.  
  140.      FT_MSHOWCRS()
  141.      FT_MSETCOORD(10,20)  // just an arbitrary place for demo
  142.  
  143. * put the unchanging stuff
  144.  
  145.      devpos( 9, 10 )
  146.      devout( "FT_MMICKEYS :" )
  147.  
  148.      devpos( 10, 10 )
  149.      devout( "FT_MGETPOS  :" )
  150.  
  151.      devpos( 11, 10 )
  152.      devout( "FT_MGETX    :" )
  153.    
  154.      devpos( 12, 10 )
  155.      devout( "FT_MGETY    :")
  156.    
  157.      devpos( 13, 10 )
  158.      devout( "FT_MGETCOORD:" )
  159.    
  160.      devpos( 14, 10 )
  161.      devout( "FT_MBUTPRS  :" )
  162.    
  163.      devpos( 16, 10 )
  164.      devout( "FT_MBUTREL  :" )
  165.  
  166.      nX := nY := 1
  167.      do while .t.
  168.  
  169. * If we are not moving then wait for movement.
  170. * This whole demo is a bit artificial in its requirements when compared 
  171. * to a "normal" CLIPPER program so some of these examples are a bit out of
  172. * the ordinary.
  173.    
  174.         DO WHILE nX=0.AND.nY=0 
  175.              FT_MMICKEYS( @nX, @nY )
  176.         ENDDO
  177. * tell the mouse driver where updates will be taking place so it can hide
  178. * the cursor when necessary. 
  179.  
  180.         FT_MCONOFF( 9, 23, 16, 53 )
  181.         nTime=-1
  182.  
  183.         devpos( 9, 23 )
  184.         devout( nX )
  185.         devout( nY )
  186.  
  187.         devpos( 10, 23 )
  188.         DEVOUT( FT_MGETPOS( @nX, @nY ) )
  189.         devout( nX )
  190.         devout( nY )
  191.  
  192.         devpos( 11, 23 )
  193.         DEVOUT(  FT_MGETX() )
  194.  
  195.         devpos( 12, 23 )
  196.         DEVOUT( FT_MGETY() )
  197.  
  198.         devpos( 13, 23 )
  199.         devout( FT_MGETCOORD( @nX, @nY ) )
  200.         devout ( nX )
  201.         devout ( nY )
  202.  
  203.         nX:=nY:=0
  204.         devpos( 14, 23 )
  205.         DEVOUT( FT_MBUTPRS(1) )
  206.         DEVOUT( FT_MBUTPRS(0,, nX, nY) )
  207.         devpos( 15, 23 )
  208.  
  209. * show only the last Press since it flashes by so quickly
  210.  
  211.         IF nX!=0.OR.nY!=0
  212.              devout( nX )
  213.              devout( nY )
  214.         endif
  215.  
  216.         nX:=nY:=0
  217.         devpos( 16, 23 )
  218.         devout( FT_MBUTREL(0,, @nX, @nY) )
  219.  
  220. * show only the last release since it flashes by so quickly
  221.  
  222.         if nX!=0.OR.nY!=0
  223.              devout( nX )
  224.              devout( nY )
  225.         endif
  226.  
  227. * Restore the cursor if it has been hidden
  228.  
  229.         FT_MSHOWCRS()
  230.  
  231.         if FT_MINREGION( 18, 11, 18, 39 )
  232.  
  233. * Change the type of cursor when in the box. Just slightly different than the
  234. * normal. The character is shown in high intensity.
  235.  
  236.            FT_MDEFCRS(0,32767,32512)
  237.            if FT_MDBLCLK(2,0,0.8)  
  238.               exit
  239.            endif
  240.         endif
  241.  
  242.         if FT_MINREGION( 18, 11, 18, 39 )
  243.  
  244. * Change the type of cursor when in the box. Just slightly different than the
  245. * normal. The character is shown in high intensity.
  246.  
  247.            FT_MDEFCRS(0,32767,32512)
  248.         else
  249.  
  250. * Put the cursor back to normal mode
  251.  
  252.            FT_MDEFCRS(0,30719,30464)
  253.         endif
  254.  
  255.         FT_MMICKEYS( @nX, @nY )
  256.      enddo
  257.  
  258.      FT_MHIDECRS()
  259.  
  260.      SETMODE(nSaveRow,nSaveCol)
  261.      setcolor( cSavClr )
  262.      restscreen( 0, 0, maxrow(), maxcol(), cSavScr )
  263.      devpos( maxrow(), 0 )
  264.  
  265. // Reset sensitivity
  266.  
  267.      FT_MSETSENS(nHoriz, nVert, nDouble)
  268.  
  269.   RETURN nil
  270.  
  271.  
  272. #endif 
  273.  
  274.  
  275.  
  276. /*
  277.  * $DOC$         
  278.  * $FUNCNAME$
  279.  *    FT_MINIT()
  280.  * $CATEGORY$
  281.  *    Keyboard/Mouse
  282.  * $ONELINER$
  283.  *    Initialize the mouse driver, vars and return status of mouse
  284.  * $SYNTAX$
  285.  *    FT_MINIT() -> lMouseStatus
  286.  * $ARGUMENTS$
  287.  *    NONE
  288.  * $RETURNS$
  289.  *    An logical representing the mouse status (.F. == mouse not installed)
  290.  * $DESCRIPTION$
  291.  *    Initializes the mouse drive, associated variables and returns mouse 
  292.  *    status. It checks to see if the mouse has been previously initialized
  293.  *    and if so it does not reinitialize. The row and column limits of mouse
  294.  *    movement is set to the maximum for the current video mode. 
  295.  *    Use FT_MSHOWCRS() to display the mouse cursor.
  296.  * $EXAMPLES$
  297.  *    IF .NOT. FT_MINIT()
  298.  *       ? "No mouse driver is installed"
  299.  *    ENDIF
  300.  * $SEEALSO$
  301.  *    FT_MRESET()
  302.  * $END$
  303.  */
  304.  
  305. FUNCTION FT_MINIT()
  306.  
  307. * If not previously initialized then try
  308.  
  309.    IF !lMinit
  310.     lMinit=(FT_MRESET()!=0)
  311.    ELSE
  312. * Reset maximum x and y limits
  313.  
  314.      FT_MYLIMIT(0,8*MAXROW())
  315.      FT_MXLIMIT(0,8*MAX